package com.xxl.job.executor.mvc.feign;

import com.web.all.common.bean.response.Result;
import com.xxl.job.executor.mvc.api.PersonnelAccessApi;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 熔断
 * 支持接口级别
 *
 * @author lc
 */
@Component
public class PersonnelAccessApiFallbackFactory implements FallbackFactory<PersonnelAccessApi> {
    private static final Logger log = LoggerFactory.getLogger(PersonnelAccessApiFallbackFactory.class);

    @Autowired
    private ExceptionDecoder exceptionDecoder;

    @Override
    public PersonnelAccessApi create(final Throwable cause) {
        log.info("PersonnelAccessApi 调用失败");
        return () ->{
            exceptionDecoder.check(cause, "PersonnelAccessApi");
            return Result.failure("PersonnelAccessApi Feign 调用失败，发生回退");
        };
    }
}
